﻿using System;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SharePointPOBox.SendToPOBoxWebPart
{
    /// <summary>WebPart to send file to POBox</summary>
    [ToolboxItemAttribute(false)]
    public class SendToPOBoxWebPart : WebPart
    {
        #region events

        /// <summary>CreateChildControls</summary>
        protected override void CreateChildControls()
        {
            SPList defaultLib = Common.GetLibrary(Common.DefaultLibraryURL, false);
            if (defaultLib != null && defaultLib.DoesUserHavePermissions(SPBasePermissions.AddListItems))
            {
                this.Controls.Add(new Button()
                                    {
                                        Text = Common.CurLngStr("SPPOBSendToPOBoxWebPart_ShowDialogButton"),
                                        OnClientClick = "ShowPopupSendToPOBoxDialog('" + SPContext.Current.Site.Url.TrimEnd("/".ToCharArray()) + "/_layouts/SharePointPOBox/Upload.aspx','" + Common.CurLngStr("SPPOBSendToPOBoxWebPart_DialogTitle") + "'); return false;"
                                    });
                this.Controls.Add(new ScriptLink()
                                    {
                                        Name = "~sitecollection/_layouts/SharePointPOBox/SPPOBSendToPOBox.js",
                                        Language = "javascript"
                                    });
            }
        }

        #endregion events
    }
}
